package emulator.analyzer.util;

import java.io.PrintStream;

import emulator.assembler.Instruction;
import emulator.hardware.HwWord;

public class CmpCommand {

	private int location;
	private Instruction instruction;
	private int operand_address;
	private int reg_source;
	private int operand;

	public CmpCommand(int location, Instruction instruction, int operand_address, int reg_source, int op)
	{
		this.location = location;
		this.instruction = instruction;
		this.operand_address = operand_address;
		this.reg_source = reg_source;
		this.operand = op; 
	}

	public void dump(PrintStream out)
	{
		out.print("@"+new HwWord(location)+": "+instruction.getOpcode() + " " + instruction.getOperand());
		out.print("  ($"+new HwWord(operand_address)+") <-> ($"+new HwWord(reg_source)+")");
		out.println();
	}

	public int getRegSource() {
		return reg_source;
	}

	public int getLocation() {
		return location;
	}

	public Instruction getInstruction() {
		return instruction;
	}

	public int getOperandAddress() {
		return operand_address;
	}

	public int getAddressFromOperand(int value, boolean is_low) {
		int new_value = value & (is_low ? 0xff00 : 0x00ff);
		return new_value | (is_low ? operand : operand << 8);
	}
}
